<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>字典管理</title>
<meta name="decorator" content="default"/>
<script type="text/javascript" src="${ctxStatic}/common/model.js"></script>
<script type="text/javascript">
	//url
	var listUrl = '${ctx}/sys/dict/';
	var cardUrl = '${ctx}/sys/dict/form';

	//按钮状态  {状态值为 0 不可用 ；1 可用}
	var buttonStatus = {};
	buttonStatus.add 	= {add:{id:'btnAdd',st:0},edit:{id:'btnEdit',st:0},save:{id:'btnSubmit',st:1},cancel:{id:'btnCancel',st:1},back:{id:'btnBack',st:1}};
	buttonStatus.edit	= {add:{id:'btnAdd',st:0},edit:{id:'btnEdit',st:0},save:{id:'btnSubmit',st:1},cancel:{id:'btnCancel',st:1},back:{id:'btnBack',st:1}};
	buttonStatus.save   = {add:{id:'btnAdd',st:1},edit:{id:'btnEdit',st:1},save:{id:'btnSubmit',st:0},cancel:{id:'btnCancel',st:0},back:{id:'btnBack',st:1}};
	buttonStatus.cancel = {add:{id:'btnAdd',st:1},edit:{id:'btnEdit',st:"${not empty dict.id?'1':'0'}"},save:{id:'btnSubmit',st:0},cancel:{id:'btnCancel',st:0},back:{id:'btnBack',st:1}}
	buttonStatus.other  = {add:{id:'btnAdd',st:1},edit:{id:'btnEdit',st:"${not empty dict.id?'1':'0'}"},save:{id:'btnSubmit',st:0},cancel:{id:'btnCancel',st:0},back:{id:'btnBack',st:1}};

	$(document).ready(function() {
		$("#inputForm").validate({
			submitHandler: function(form){
				loading('正在提交，请稍等...');
				form.submit();
			},
			errorContainer: "#messageBox",
			errorPlacement: function(error, element) {
				$("#messageBox").text("输入有误，请先更正。");
				if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
					error.appendTo(element.parent().parent());
				} else {
					error.insertAfter(element);
				}
			}
		});
		
		var currentOpt = "${opt}";
		if(currentOpt==null||currentOpt==''){
			currentOpt = 'other';
		}
		var btnStatus = buttonStatus[currentOpt];
		freshButtonStatus(btnStatus);
		if(currentOpt=='add' || currentOpt=='edit'){
			setAllPageEnable(jQuery("#formAreaId"));
		}else{
			setAllPageDisable(jQuery("#formAreaId"));
		}
			
		if("${message}"!=""){
			 alertx("${message}");
		}
		
		var treeSelectNodes = parent.getSelectNode();
		if(treeSelectNodes!=null && treeSelectNodes.length>0){
			var treeNode = treeSelectNodes[0];
			if(!treeNode.hasChild){
				if(jQuery('[name="type"]').val()==null || jQuery('[name="type"]').val()==''){
					jQuery('[name="type"]').val(treeNode.id);
					jQuery('[name="description"]').val(treeNode.name);
				}
			}
		}
		
	});
		
	function add(){ //新增记录
		var url = cardUrl+"?opt=add";
		window.location.href = url;
	}
	
	function edit(){ //修改记录
		var btnStatus = buttonStatus['edit'];
		freshButtonStatus(btnStatus);
		setAllPageEnable(jQuery("#formAreaId"));
		jQuery("#formAreaId").find("[name='publishstatus.id']").attr("disabled", true);
	}
	
	function cancel(){ //取消操作
		var btnStatus = buttonStatus['cancel'];
		freshButtonStatus(btnStatus);
		setAllPageDisable(jQuery("#formAreaId"));
		jQuery('#inputForm')[0].reset();
	}
	
	function back(){ //返回
		var btnStatus = buttonStatus['other'];
		freshButtonStatus(btnStatus);
		setAllPageDisable(jQuery("#formAreaId"));
		parent.queryListPage();
	}
	</script>
</head>
<body>
	
	<form:form id="inputForm" modelAttribute="dict" action="${ctx}/sys/dict/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		
		<div class="breadcrumb form-search" id="toolButtonId">
			<shiro:hasPermission name="sys:dictitem:edit">
				<input id="btnAdd" class="btn btn-primary" type="button" value="新 增" onclick="add()"/>&nbsp;
				<input id="btnEdit" class="btn btn-primary" type="button" value="修 改" onclick="edit()"/>&nbsp;
				<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;
				<input id="btnCancel" class="btn" type="button" value="取 消" onclick="cancel()"/>
			</shiro:hasPermission>
			<input id="btnBack" class="btn" type="button" value="返 回" onclick="back()"/>
		</div>
		
		<div id="formAreaId">
		
		<div class="control-group">
			<label class="control-label">键值:</label>
			<div class="controls">
				<form:input path="value" htmlEscape="false" maxlength="50" class="required"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">标签:</label>
			<div class="controls">
				<form:input path="label" htmlEscape="false" maxlength="50" class="required"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">类型:</label>
			<div class="controls">
				<form:input path="type" htmlEscape="false" maxlength="50" class="required abc"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">描述:</label>
			<div class="controls">
				<form:input path="description" htmlEscape="false" maxlength="50" class="required"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">排序:</label>
			<div class="controls">
				<form:input path="sort" htmlEscape="false" maxlength="11" class="required digits"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注:</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="3" maxlength="200" class="input-xlarge"/>
			</div>
		</div>
		
		</div>
	</form:form>
	
	<div style="height: 50px;width: 100%;"></div>
	
</body>
</html>